home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-09-28 | 3.7 KB | 133 lines |
- '***************************
- '* AMOS Professional *
- '* *
- '* ARRAYS *
- '* *
- '* (c) Europress Software *
- '* *
- '* Ronnie Simpson *
- '***************************
- '
- '-------------------------------------------
- 'SETTING UP
- '-------------------------------------------
- ' +----->The command (reserves the memory required)
- ' | +----->The variable
- ' | | +----->The number of elements
- ' | | |
- ' ^ ^ ^
- ' Dim A(10)
- '
- '-------------------------------------------
- 'GIVING AN ARRAY ELEMENT A VALUE
- '-------------------------------------------
- ' +----->The array variable
- ' | +----->The element number
- ' | | +----->The value to be stored
- ' | | |
- ' ^ ^ ^
- ' A(5)=100
- '
- '-------------------------------------------
- 'EXAMPLE USAGE
- '-------------------------------------------
- ' +----->Print the value stored in 2nd. element of array A()
- ' | +----->The array variable
- ' | | +----->The element number
- ' | | |
- ' ^ ^ ^
- ' Print A(2)
- '
- '-------------------------------------------
- 'NOTES
- '-------------------------------------------
- 'Use the Dim command at the start of your program (reserves memory).
- 'Do not try to re-dimension an array that already exists.
- 'Element numbers start from 0 eg. Dim A(10) gives 11 elements A(0)-A(10).
- 'Array variables may be any legal name eg. A(),NAME$(),HIGH_SCORE().
- 'Arrays can be of any type of variables eg. string$ A$(), real numbers N#().
- 'Maximum of 65,000 elements per dimension.
- '
- '-------------------------------------------
- 'WORKING EXAMPLE
- '-------------------------------------------
- 'The following program sets up the array SQUARES(8,5) and fills the elements
- 'with random numbers between 0 and 9.
- 'A grid is drawn on the screen showing the contents of the array reading
- 'horizontally and vertically.
- 'The computer then uses this array to calculate and display the totals of
- 'each line both across and down.
- '
- '-------------------------------------------
- '
- Rem *** Dimension the array and reserve the memory
- '
- Dim SQUARES(8,5)
- '
- '
- Rem *** Tidy up the screen
- '
- Curs Off : Flash Off : Hide : Paper 0 : Cls 0 : Set Paint 1
- Palette $0,$F00,$F0,$F,$FF0,$F0F,$FF,$F70,$7F,$70F,$F07,$333,$666,$999,$CCC,$FFF
- '
- '
- Rem *** Start of loop to repeat the program
- '
- Repeat
- '
- '
- Rem *** Print out instructions
- '
- Pen 4 : Locate 0,0 : Centre "RIGHT mouse key to stop program"
- Pen 5 : Locate 0,2 : Centre "LEFT mouse key for another grid"
- '
- '
- Rem *** Fill the array with random numbers and show them on screen
- '
- For HORIZONTAL=1 To 8
- For VERTICAL=1 To 5
- NUMBER=Rnd(9)
- SQUARES(HORIZONTAL,VERTICAL)=NUMBER
- Ink 3,3,4 : Bar HORIZONTAL*30,VERTICAL*30 To HORIZONTAL*30+30,VERTICAL*30+30
- Ink 6 : Text HORIZONTAL*30+3,VERTICAL*30+18,Str$(NUMBER)
- Next
- Next
- '
- '
- Rem *** find the totals of the vertical columns
- '
- For HORIZONTAL=1 To 8
- ANSWER=0
- For VERTICAL=1 To 5
- ANSWER=ANSWER+SQUARES(HORIZONTAL,VERTICAL)
- Next
- Ink 8,0 : Text HORIZONTAL*30,192,Str$(ANSWER)+" "
- Next
- '
- '
- Rem *** now find the totals of the horizontal lines
- '
- For VERTICAL=1 To 5
- ANSWER=0
- For HORIZONTAL=1 To 8
- ANSWER=ANSWER+SQUARES(HORIZONTAL,VERTICAL)
- Next
- Text 271,VERTICAL*30+18,Str$(ANSWER)+" "
- Next
- '
- '
- Rem *** wait for the user to click a mouse button
- '
- Do
- Exit If Mouse Key
- Loop
- '
- '
- Rem *** If left mouse key then repeat
- '
- Until Mouse Key=2
- '
- '
- Rem *** return to editor when right mouse key has been pressed
- '
- Edit